package com.hdw.auth.controller;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import com.hdw.common.base.BaseResult;
import com.hdw.common.constant.CommonResultConstant;
import com.hdw.common.base.BaseException;
import com.hdw.auth.api.BaseAuthUseService;
import com.hdw.auth.bean.model.BaseAuthUse;
import org.springframework.util.StringUtils;
import com.hdw.common.vo.PaginationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * baseAuthUse控制器
 * Created by liujunlei on 2022/01/05.
 */
@RestController
@RequestMapping("/med/baseAuthUse/")
@Api(tags="开发中")
public class BaseAuthUseController {

    @Autowired
    BaseAuthUseService baseAuthUseService;

    @ApiOperation(value="分页查询")
    @RequestMapping(value="findByPage", method=RequestMethod.POST)
    public BaseResult findByPage(@RequestBody BaseAuthUse baseAuthUse, Integer pageNum, Integer pageSize) {
        PaginationVO<BaseAuthUse> pageVO = baseAuthUseService.findPageByModel(baseAuthUse, pageNum, pageSize);
        return new BaseResult(CommonResultConstant.SUCCESS, pageVO);
    }

    @ApiOperation(value="保存")
    @ApiImplicitParam(name="baseAuthUse", value="实体", paramType="body", required=true, dataType="BaseAuthUse")
    @RequestMapping(value="insert", method=RequestMethod.POST)
    public BaseResult insert(@RequestBody BaseAuthUse baseAuthUse, HttpServletRequest request)  {
        int num = baseAuthUseService.insertSelective(baseAuthUse);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="详情")
    @ApiImplicitParam(name="idUse", value="主键", paramType="query", required=true, dataType="Long")
    @RequestMapping(value="getById", method=RequestMethod.GET)
    public BaseResult getById(Long idUse, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idUse)){
            throw new BaseException("请选择要编辑的项");
        }
        BaseAuthUse baseAuthUse = baseAuthUseService.getById(idUse);
        return new BaseResult(CommonResultConstant.SUCCESS, baseAuthUse);
    }

    @ApiOperation(value="修改")
    @ApiImplicitParam(name="baseAuthUse", value="实体", paramType="body", required=true, dataType="BaseAuthUse")
    @RequestMapping(value="update", method=RequestMethod.POST)
    public BaseResult update(@RequestBody BaseAuthUse baseAuthUse, HttpServletRequest request)  {
        int num = baseAuthUseService.updateByIdSelective(baseAuthUse);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="根据主键删除")
    @ApiImplicitParam(name="idUse", value="主键", paramType="query", required=true, dataType="Long")
    @RequestMapping(value="delete", method=RequestMethod.GET)
    public BaseResult delete(Long idUse, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idUse)){
            throw new BaseException("请选择要删除的项");
        }
        int num = baseAuthUseService.deleteById(idUse);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }
}
